Skip to content

jextract/jni: Implement generic equals method#778

Merged
ktoso merged 3 commits into
swiftlang:mainfrom
sidepelican:equatable
Jun 3, 2026
Merged

jextract/jni: Implement generic equals method#778
ktoso merged 3 commits into
swiftlang:mainfrom
sidepelican:equatable

Conversation

@sidepelican
Copy link
Copy Markdown
Contributor

In Java, every Object has an equals method.
Conceptually, Swift's Equatable protocol serves the exact same purpose as Java's equals.

This PR implements a generic equals method, enabling all JNISwiftInstance types to leverage Swift's Equatable comparison directly through the standard Java equals method.

@sidepelican sidepelican requested a review from ktoso as a code owner June 2, 2026 06:03
Copy link
Copy Markdown
Collaborator

@ktoso ktoso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat! I wonder if we can nicely do hash code as well; otherwise we're breaking the contract of always having to implement "both"

@sidepelican
Copy link
Copy Markdown
Contributor Author

sidepelican commented Jun 2, 2026

I forgot to consider hashCode.
It's a bit challenging (Only Equatable types cannot provide hashCode)

@sidepelican
Copy link
Copy Markdown
Contributor Author

Implemented hashCode().
I made a compromise regarding types that only implement Equatable.

@ktoso
Copy link
Copy Markdown
Collaborator

ktoso commented Jun 2, 2026

Looks good, let’s add a test putting swift values into a java set maybe or
Something like that?

@ktoso ktoso merged commit 1ce28de into swiftlang:main Jun 3, 2026
41 checks passed
@sidepelican sidepelican deleted the equatable branch June 3, 2026 03:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants